<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item">

                    <!-- <div class="layui-form-item layui-inline">
                   <label class="layui-form-label">轮次id</label>
                   <div class="layui-input-inline">
                       <input type="text" name="lcid" placeholder="" class="layui-input">
                   </div>
               </div>    -->
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="cyaccount" placeholder="参与玩家(账号)" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="cyactorid" placeholder="参与玩家(actorid)" class="layui-input">
                        </div>
                    </div>
                    <!-- <div class="layui-form-item layui-inline">
                   <div class="layui-input-inline">
                       <input type="text" name="cyqufu" placeholder="区服名称" class="layui-input">
                   </div>
               </div>    -->
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <div class="layui-input-inline">
                                <select name="cyqufuid" lay-search>
                                    <option value="">服务器ID</option>
                                    {volist name="ServerLs" id="server"}
                                    <option value="{$server.sid}">{$server.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <select name="istc" id="istc" lay-search>
                                <option value="">是否头筹</option>
                                <option value="1">否</option>
                                <option value="2">是</option>
                            </select>
                        </div>

                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>

    <script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
            <button class="pear-btn pear-btn-md" lay-event="recycle">
		        <i class="layui-icon layui-icon-delete"></i>
		        回收站
		    </button>
		</script>
    <script type="text/html" id="istcTpl">
            {{# if(d.istc == '1'){ }}
                <span>否</span>
            {{# }else if(d.istc == '2'){ }}
                <span>是</span>
            {{# }else{ }}
                <span>异常</span>
            {{# } }}
        </script>



    <script type="text/html" id="options">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</script>
    <script>
        layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;
            let common = layui.common;
            let laydate = layui.laydate;
            let MODULE_PATH = "{$Request.root}/gm.tclpaneltzb/";

            let cols = [
                [{
                    type: 'checkbox'
                }, {
                    field: "id",
                    title: "id",
                    unresize: "true",
                    align: "center",
                    hide:true
                }, {
                    field: "lcid",
                    title: "轮次",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "cyaccount",
                    title: "玩家账号",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "cyqufu",
                    title: "区服名称",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "cyqufuid",
                    title: "区服ID",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "istc",
                    title: "是否头筹",
                    unresize: "true",
                    align: "center",
                    templet: '#istcTpl'
                }, {
                    field: "create_time",
                    title: "创建时间",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "update_time",
                    title: "更新时间",
                    unresize: "true",
                    align: "center"
                }
                //, {
                //    title: '操作',
                //    toolbar: '#options',
                //    unresize: true,
                //    align: 'center',
                //    width: 180,
                //}
                ]
            ]

            table.render({
                elem: '#dataTable',
                url: MODULE_PATH + 'index',
                page: true,
                cols: cols,
                limit: 10,
                limits: [10, 30, 50, 100, 200, 500, 1000],
                cellMinWidth: 100,
                skin: 'line',
                //toolbar: '#toolbar',
                defaultToolbar: [{
                    title: '刷新',
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
            });

            table.on('tool(dataTable)', function (obj) {
                if (obj.event === 'remove') {
                    window.remove(obj);
                } else if (obj.event === 'edit') {
                    window.edit(obj);
                }
            });

            table.on('toolbar(dataTable)', function (obj) {
                if (obj.event === 'add') {
                    window.add();
                } else if (obj.event === 'refresh') {
                    window.refresh();
                } else if (obj.event === 'batchRemove') {
                    window.batchRemove(obj);
                } else if (obj.event === 'recycle') {
                    window.recycle(obj);
                }
            });

            form.on('submit(query)', function (data) {
                table.reload('dataTable', {
                    where: data.field,
                    page: { curr: 1 }
                })

                return false;
            });

            //弹出窗设置 自己设置弹出百分比
            function screen() {
                if (typeof width !== 'number' || width === 0) {
                    width = $(window).width() * 0.8;
                }
                if (typeof height !== 'number' || height === 0) {
                    height = $(window).height() - 20;
                }
                return [width + 'px', height + 'px'];
            }

            window.add = function () {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '新增头筹投注记录',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'add'
                });
            }

            window.edit = function (obj) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改头筹投注记录',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'edit/id/' + obj.data['id']
                });
            }

            window.recycle = function () {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '回收站',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'recycle',
                    cancel: function () {
                        table.reload('dataTable');
                    }
                });
            }


            window.remove = function (obj) {
                layer.confirm('确定要删除该头筹投注记录', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: MODULE_PATH + 'remove',
                        data: { id: obj.data['id'] },
                        dataType: 'json',
                        type: 'POST',
                        success: function (res) {
                            layer.close(loading);
                            //判断有没有权限
                            if (res && res.code == 999) {
                                layer.msg(res.msg, {
                                    icon: 5,
                                    time: 2000,
                                })
                                return false;
                            } else if (res.code == 200) {
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    obj.del();
                                });
                            } else {
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }

            window.batchRemove = function (obj) {
                let data = table.checkStatus(obj.config.id).data;
                if (data.length === 0) {
                    layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                    return false;
                }
                var ids = []
                var hasCheck = table.checkStatus('dataTable')
                var hasCheckData = hasCheck.data
                if (hasCheckData.length > 0) {
                    $.each(hasCheckData, function (index, element) {
                        ids.push(element.id)
                    })
                }
                layer.confirm('确定要删除这些头筹投注记录', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: MODULE_PATH + 'batchRemove',
                        data: { ids: ids },
                        dataType: 'json',
                        type: 'POST',
                        success: function (res) {
                            layer.close(loading);
                            //判断有没有权限
                            if (res && res.code == 999) {
                                layer.msg(res.msg, {
                                    icon: 5,
                                    time: 2000,
                                })
                                return false;
                            } else if (res.code == 200) {
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('dataTable');
                                });
                            } else {
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }

            window.refresh = function (param) {
                table.reload('dataTable');
            }
        })
    </script>
</body>

</html>